
package fragment;

import fr.irit.smac.muadl.impl.j.Architecture;
import fragment.AdapterMessageHandler;
import fragment.QuasiComponentMessageHandler;
import fragment.AdapterLifeCycle;
import fragment.QuasiComponentLifeCycle;
import fragment.AdapterGeneration;
import fragment.QuasiComponentGeneration;
import fragment.AdapterReservation;
import fragment.QuasiComponentReservation;
import fragment.AdapterStimulation;
import fragment.QuasiComponentStimulation;
import fragment.AdapterProcessHandler;
import fragment.QuasiComponentProcessHandler;
import fragment.AdapterContactHandler;
import fragment.QuasiComponentContactHandler;
import fragment.AdapterExternalViewer;
import fragment.QuasiComponentExternalViewer;
import fragment.AdapterBehavior;
import fragment.QuasiComponentBehavior;


public class FragmentMediator extends Architecture {

	private QuasiComponentMessageHandler MessageHandler;
	private QuasiComponentLifeCycle LifeCycle;
	private QuasiComponentGeneration Generation;
	private QuasiComponentReservation Reservation;
	private QuasiComponentStimulation Stimulation;
	private QuasiComponentProcessHandler ProcessHandler;
	private QuasiComponentContactHandler ContactHandler;
	private QuasiComponentExternalViewer ExternalViewer;
	private QuasiComponentBehavior Behavior;

	protected FragmentMediator(QuasiComponentMessageHandler _MessageHandler, QuasiComponentLifeCycle _LifeCycle, QuasiComponentGeneration _Generation, QuasiComponentReservation _Reservation, QuasiComponentStimulation _Stimulation, QuasiComponentProcessHandler _ProcessHandler, QuasiComponentContactHandler _ContactHandler, QuasiComponentExternalViewer _ExternalViewer, QuasiComponentBehavior _Behavior) {
		
		change(_MessageHandler);
		
		change(_LifeCycle);
		
		change(_Generation);
		
		change(_Reservation);
		
		change(_Stimulation);
		
		change(_ProcessHandler);
		
		change(_ContactHandler);
		
		change(_ExternalViewer);
		
		change(_Behavior);
		
	}
	
	public void start() {
		
		MessageHandler.start();
		
		LifeCycle.start();
		
		Generation.start();
		
		Reservation.start();
		
		Stimulation.start();
		
		ProcessHandler.start();
		
		ContactHandler.start();
		
		ExternalViewer.start();
		
		Behavior.start();
		
	}
	
	public void change(QuasiComponentMessageHandler _MessageHandler) {
		
		if (MessageHandler != null) {
			transferState(MessageHandler, _MessageHandler);
		}
		
		setAdapter(_MessageHandler, new FragmentMessageHandlerAdapter(this));
		MessageHandler = _MessageHandler;
	}
	
	public void change(QuasiComponentLifeCycle _LifeCycle) {
		
		setAdapter(_LifeCycle, new FragmentLifeCycleAdapter(this));
		LifeCycle = _LifeCycle;
	}
	
	public void change(QuasiComponentGeneration _Generation) {
		
		setAdapter(_Generation, new FragmentGenerationAdapter(this));
		Generation = _Generation;
	}
	
	public void change(QuasiComponentReservation _Reservation) {
		
		setAdapter(_Reservation, new FragmentReservationAdapter(this));
		Reservation = _Reservation;
	}
	
	public void change(QuasiComponentStimulation _Stimulation) {
		
		setAdapter(_Stimulation, new FragmentStimulationAdapter(this));
		Stimulation = _Stimulation;
	}
	
	public void change(QuasiComponentProcessHandler _ProcessHandler) {
		
		setAdapter(_ProcessHandler, new FragmentProcessHandlerAdapter(this));
		ProcessHandler = _ProcessHandler;
	}
	
	public void change(QuasiComponentContactHandler _ContactHandler) {
		
		setAdapter(_ContactHandler, new FragmentContactHandlerAdapter(this));
		ContactHandler = _ContactHandler;
	}
	
	public void change(QuasiComponentExternalViewer _ExternalViewer) {
		
		setAdapter(_ExternalViewer, new FragmentExternalViewerAdapter(this));
		ExternalViewer = _ExternalViewer;
	}
	
	public void change(QuasiComponentBehavior _Behavior) {
		
		setAdapter(_Behavior, new FragmentBehaviorAdapter(this));
		Behavior = _Behavior;
	}
	

	
	public void send(message.Message message) {
		 this.MessageHandler.send(message);
	}
	
	public java.util.Vector<message.Message> receive() {
		return this.MessageHandler.receive();
	}
	
	public void doSuicide() {
		 this.LifeCycle.doSuicide();
	}
	
	public void generate() {
		 this.Generation.generate();
	}
	
	public void stopGenerating() {
		 this.Generation.stopGenerating();
	}
	
	public java.util.Vector<java.lang.String> getGenerationCapabilities() {
		return this.Generation.getGenerationCapabilities();
	}
	
	public void reserve(java.lang.String mmme) {
		 this.Reservation.reserve(mmme);
	}
	
	public void release(java.lang.String mmme) {
		 this.Reservation.release(mmme);
	}
	
	public void releaseAll() {
		 this.Reservation.releaseAll();
	}
	
	public java.util.Vector<java.lang.String> requiredElements() {
		return this.Reservation.requiredElements();
	}
	
	public boolean allNeededElementReserved() {
		return this.Reservation.allNeededElementReserved();
	}
	
	public int getCurrentStimulation() {
		return this.Stimulation.getCurrentStimulation();
	}
	
	public void updateSendStimulation(java.lang.String id,int val) {
		 this.Stimulation.updateSendStimulation(id,val);
	}
	
	public void updateReceivedStimulation(java.lang.String id,int val) {
		 this.Stimulation.updateReceivedStimulation(id,val);
	}
	
	public void stopStimulateAll() {
		 this.Stimulation.stopStimulateAll();
	}
	
	public void updateAllStimulation() {
		 this.Stimulation.updateAllStimulation();
	}
	
	public java.util.Hashtable<String,Integer> getStimulators() {
		return this.Stimulation.getStimulators();
	}
	
	public java.util.Vector<java.lang.String> getStimuled() {
		return this.Stimulation.getStimuled();
	}
	
	public void cancelStimulation(java.lang.String id) {
		 this.Stimulation.cancelStimulation(id);
	}
	
	public long getProcess() {
		return this.ProcessHandler.getProcess();
	}
	
	public void updateProcess() {
		 this.ProcessHandler.updateProcess();
	}
	
	public fragment.Fragment getFragment(java.lang.String id) {
		return this.ContactHandler.getFragment(id);
	}
	
	public java.util.Vector<fragment.Fragment> findAllPotentialGenerators(java.lang.String mmme) {
		return this.ContactHandler.findAllPotentialGenerators(mmme);
	}
	
	public boolean isElementPresent(java.lang.String mmme) {
		return this.ContactHandler.isElementPresent(mmme);
	}
	
	public boolean isMMMEGivenByUser(java.lang.String mmme) {
		return this.ContactHandler.isMMMEGivenByUser(mmme);
	}
	
	public void informOfGeneration() {
		 this.ContactHandler.informOfGeneration();
	}
	
	public void informStoppingGeneration() {
		 this.ContactHandler.informStoppingGeneration();
	}
	
	public void informOfReservation(java.lang.String mmme) {
		 this.ContactHandler.informOfReservation(mmme);
	}
	
	public void informOfRelease(java.lang.String mmme) {
		 this.ContactHandler.informOfRelease(mmme);
	}
	
	public boolean nobodyNeed(java.lang.String mmme) {
		return this.ContactHandler.nobodyNeed(mmme);
	}
	
	public java.lang.String getId() {
		return this.ExternalViewer.getId();
	}
	
	public fragment.AgentState currentState() {
		return this.ExternalViewer.currentState();
	}
	
	public long currentProcess() {
		return this.ExternalViewer.currentProcess();
	}
	
	public void step() {
		 this.Behavior.step();
	}
	
	public fragment.AgentState getState() {
		return this.Behavior.getState();
	}
	

	
	private class FragmentMessageHandlerAdapter implements AdapterMessageHandler {
		private final FragmentMediator arch;
		FragmentMessageHandlerAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		

	}
	
	private class FragmentLifeCycleAdapter implements AdapterLifeCycle {
		private final FragmentMediator arch;
		FragmentLifeCycleAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public void step() {
			arch.step();
		}
		

	}
	
	private class FragmentGenerationAdapter implements AdapterGeneration {
		private final FragmentMediator arch;
		FragmentGenerationAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public void informOfGeneration() {
			arch.informOfGeneration();
		}
		
		@Override
		public void informStoppingGeneration() {
			arch.informStoppingGeneration();
		}
		

	}
	
	private class FragmentReservationAdapter implements AdapterReservation {
		private final FragmentMediator arch;
		FragmentReservationAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public void informOfReservation(java.lang.String arg0) {
			arch.informOfReservation(arg0);
		}
		
		@Override
		public void informOfRelease(java.lang.String arg0) {
			arch.informOfRelease(arg0);
		}
		

	}
	
	private class FragmentStimulationAdapter implements AdapterStimulation {
		private final FragmentMediator arch;
		FragmentStimulationAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public fragment.Fragment getFragment(java.lang.String arg0) {
			return arch.getFragment(arg0);
		}
		

	}
	
	private class FragmentProcessHandlerAdapter implements AdapterProcessHandler {
		private final FragmentMediator arch;
		FragmentProcessHandlerAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public fragment.AgentState getState() {
			return arch.getState();
		}
		
		@Override
		public java.util.Vector<java.lang.String> getGenerationCapabilities() {
			return arch.getGenerationCapabilities();
		}
		
		@Override
		public java.util.Hashtable<String,Integer> getStimulators() {
			return arch.getStimulators();
		}
		
		@Override
		public java.util.Vector<fragment.Fragment> findAllPotentialGenerators(java.lang.String arg0) {
			return arch.findAllPotentialGenerators(arg0);
		}
		
		@Override
		public int getCurrentStimulation() {
			return arch.getCurrentStimulation();
		}
		
		@Override
		public java.lang.String getId() {
			return arch.getId();
		}
		
		@Override
		public java.util.Vector<java.lang.String> requiredElements() {
			return arch.requiredElements();
		}
		
		@Override
		public fragment.Fragment getFragment(java.lang.String arg0) {
			return arch.getFragment(arg0);
		}
		

	}
	
	private class FragmentContactHandlerAdapter implements AdapterContactHandler {
		private final FragmentMediator arch;
		FragmentContactHandlerAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		

	}
	
	private class FragmentExternalViewerAdapter implements AdapterExternalViewer {
		private final FragmentMediator arch;
		FragmentExternalViewerAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public fragment.AgentState getState() {
			return arch.getState();
		}
		
		@Override
		public long getProcess() {
			return arch.getProcess();
		}
		

	}
	
	private class FragmentBehaviorAdapter implements AdapterBehavior {
		private final FragmentMediator arch;
		FragmentBehaviorAdapter(FragmentMediator _arch) {
			arch = _arch;
		}
		
	
		
		@Override
		public void doSuicide() {
			arch.doSuicide();
		}
		
		@Override
		public void generate() {
			arch.generate();
		}
		
		@Override
		public void stopGenerating() {
			arch.stopGenerating();
		}
		
		@Override
		public java.util.Vector<java.lang.String> getGenerationCapabilities() {
			return arch.getGenerationCapabilities();
		}
		
		@Override
		public void reserve(java.lang.String arg0) {
			arch.reserve(arg0);
		}
		
		@Override
		public void release(java.lang.String arg0) {
			arch.release(arg0);
		}
		
		@Override
		public void releaseAll() {
			arch.releaseAll();
		}
		
		@Override
		public java.util.Vector<java.lang.String> requiredElements() {
			return arch.requiredElements();
		}
		
		@Override
		public boolean allNeededElementReserved() {
			return arch.allNeededElementReserved();
		}
		
		@Override
		public int getCurrentStimulation() {
			return arch.getCurrentStimulation();
		}
		
		@Override
		public void updateReceivedStimulation(java.lang.String arg0,int arg1) {
			arch.updateReceivedStimulation(arg0,arg1);
		}
		
		@Override
		public void updateSendStimulation(java.lang.String arg0,int arg1) {
			arch.updateSendStimulation(arg0,arg1);
		}
		
		@Override
		public void cancelStimulation(java.lang.String arg0) {
			arch.cancelStimulation(arg0);
		}
		
		@Override
		public void stopStimulateAll() {
			arch.stopStimulateAll();
		}
		
		@Override
		public void updateAllStimulation() {
			arch.updateAllStimulation();
		}
		
		@Override
		public java.util.Vector<fragment.Fragment> findAllPotentialGenerators(java.lang.String arg0) {
			return arch.findAllPotentialGenerators(arg0);
		}
		
		@Override
		public boolean isElementPresent(java.lang.String arg0) {
			return arch.isElementPresent(arg0);
		}
		
		@Override
		public boolean isMMMEGivenByUser(java.lang.String arg0) {
			return arch.isMMMEGivenByUser(arg0);
		}
		
		@Override
		public boolean nobodyNeed(java.lang.String arg0) {
			return arch.nobodyNeed(arg0);
		}
		
		@Override
		public void updateProcess() {
			arch.updateProcess();
		}
		
		@Override
		public java.lang.String getId() {
			return arch.getId();
		}
		
		@Override
		public java.util.Vector<message.Message> receive() {
			return arch.receive();
		}
		

	}
	
}
